package com.open.validator;




import com.open.validator.impl.LengthValidator;

import javax.validation.Constraint;
import javax.validation.Payload;
import javax.validation.constraints.Size;
import java.lang.annotation.Documented;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
 * @author: system
 * @Date: 2024/4/19 15:10
 * @Version: V1.0
 * @description: desc:长度校验，依赖字段有值或者为指定值时
 */
@Documented
@Constraint(validatedBy = {LengthValidator.class})
@Target({ANNOTATION_TYPE, TYPE})
@Repeatable(Length.List.class)
@Retention(RUNTIME)
public @interface Length {

    String message() default "the string length must be between min and max!";

    Class<?>[] groups() default {};

    Class<? extends Payload>[] payload() default {};

    /**
     * @return size the element must be higher or equal to
     */
    int min() default 0;

    /**
     * @return size the element must be lower or equal to
     */
    int max() default Integer.MAX_VALUE;

    /**
     * @return Decorated fields
     */
    String field();

    /**
     * @return Dependent field
     */
    String depField();

    /**
     * @return Value of dependent field
     */
    String[] depValue() default {};

    /**
     * Defines several {@link Size} annotations on the same element.
     *
     * @see Size
     */
    @Target({ANNOTATION_TYPE, TYPE})
    @Retention(RUNTIME)
    @Documented
    @interface List {

        Length[] value();
    }
}
